package com.celer.flex.service.impl;

import com.celer.flex.entity.User;
import com.celer.flex.mapper.UserMapper;
import com.celer.flex.service.UserService;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

import static com.celer.flex.entity.table.UserTableDef.USER;

@RequiredArgsConstructor
@Slf4j
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User>
        implements UserService {

    private final UserMapper userMapper;

    @Override
    public List<User> getByPhone(String phone) {
        return userMapper.selectListByQuery(QueryWrapper.create()
                .where(USER.PHONE.eq(phone)));
    }

    @Override
    public User saveUser(User user) {
        int result =  userMapper.insert(user);
        return result > 0 ? user : null;
    }
}
